require("../util.js");
require("../component/components.js");
require("../../jsMt/util.js");
var userInfo=JSON.parse(sessionStorage.getItem("userInfo"));
// if(!userInfo){
//     location.href="/loginIndex"
// }
var vm = new Vue({
    el:"#paymentOK",
    data:{
        isShare:false,
        name:"",
        type:"",   // 1.支付成功   2.拼团成功  3、拼团失败
        user:{},
        // loginUid:userInfo.loginUid,
        couponId:"",
        integral:"",
        coupons:{},
        collageOrderId:"",
        hours:"",//时
        minutes:"",//分
        seconds:""//秒
    },
    mounted:function(){
        this.searchObject = this.getQueryStringArgs();
        this.type=this.searchObject&&this.searchObject.type;
        if(this.type==1){   //支付成功
            this.name="支付成功";
            this.couponId=this.searchObject&&this.searchObject.couponId;
            this.integral=this.searchObject&&this.searchObject.money;
        }else if(this.type==2){
            this.name="发起成功";
            this.collageOrderId=this.searchObject&&this.searchObject.collageOrderId;
            this.getCouponByCouponId();
        }else{
            this.name="发起失败";
        }

    },
    methods:{
        //后退
        getBack: function () {
            history.go(-1);
        },
        bgimg:function(url){
            url = url?url:"";
            return {
                "background-image":'url("'+url+'"),url("")'
            }
        },
        /*获取查询字符对象*/
        getQueryStringArgs: function () {
            //取得查询字符串并去掉开头的问号
            var qs = (location.search.length > 0 ? location.search.substring(1) : ""),
                args = {},
                items = qs.length ? qs.split("&") : [],
                item = null,
                name = null,
                value = null,
                len = items.length;
            for (var i = 0; i < len; i++) {
                item = items[i].split("=");
                name = item[0];
                value = item[1];
                if (name.length) {
                    args[name] = value;
                }
            }
            return args;
        },
        //乐购-订单详情
        getCouponByCouponId:function(){
            var that=this,data;
            data={
                orderNumber:that.collageOrderId
            };
            this.ajax({url:"/purchase/getCollageByOrderNumber",data:data,dataType:"json",method:"post"},function(b){
                if(b.json.code==0&&b.json.data){
                    that.coupons=b.json.data;
                    that.compareDate(that.coupons.currentTime,that.coupons.endDate);
                    that.user=that.coupons.list[0];
                }else{
                    vm.$refs.prompt.toast("获取详情失败！")
                }
            });
        },
        compareDate:function(startDate,endDate){
            var that=this;
            startDate = new Date(startDate.replace(/-/g, "/"));
            endDate = new Date(endDate.replace(/-/g, "/"));
            // console.log(endDate)
            var ms = endDate.getTime() - startDate.getTime();
            if (ms < 0){
                return 0;
            }
            //计算出小时数
            var hours=Math.floor(ms/(3600*1000));
            //计算相差分钟数
            var leave2=ms%(3600*1000);        //计算小时数后剩余的毫秒数
            var minutes=Math.floor(leave2/(60*1000));
            //计算相差秒数
            var leave3=leave2%(60*1000);      //计算分钟数后剩余的毫秒数
            var seconds=Math.round(leave3/1000);
            that.hours=hours;
            that.minutes=minutes;
            that.seconds=seconds;
            if(that.hours>=0&&that.minutes>=0&&that.seconds>0){
                a=setInterval(this.leftTimer,1000);
            }
        },
        //时分秒倒计时
        leftTimer:function(){
            var that=this;
            that.hours=Number(that.hours);
            that.minutes=Number(that.minutes);
            that.seconds=Number(that.seconds);
            if(that.hours==0&&that.minutes==0&&that.seconds==0){
                clearInterval(a);
            }else{
                that.seconds--;
                if(that.seconds == 0){
                    that.minutes--;
                    that.seconds = 59;
                }
                if(that.minutes < 0 && that.hours > 0){
                    that.hours--;
                    that.minutes = 59;
                }
                if (that.hours <= 9) that.hours = '0' + that.hours;
                if (that.minutes <= 9) that.minutes = '0' + that.minutes;
                if (that.seconds <= 9) that.seconds = '0' + that.seconds;
            }
        },
        getShare:function(){
            this.isShare=!this.isShare;
        },
        getChoice:function(num){
            if(num==1){
                location.href="/friend/choiceList?number=7&postId="+this.collageOrderId;
            }else{
                location.href="/friend/forward?number=7&postId="+this.collageOrderId;
            }
        },
        //跳转页面
        getNext:function(type){
            if(type==1){
                location.href="/purchase/collageInfo?collageOrderId="+this.collageOrderId;
            }else if(type==2){
                location.href="/purchase";
            }
        }
    }
});
function checkTime(i){ //将0-9的数字前面加上0，例1变为01
    if(i<10){
        i = "0" + i;
    }
    return i;
}
